﻿// <copyright file="GameProviderExtension.cs" company="Ecole Normale Supérieure">
// Released under GPLv2
// </copyright>
// <summary>Provide extension feature to IGameProvider.</summary>

namespace Sqwarea.Persistence
{
    using System.Drawing;
    using Sqwarea.Persistence.Azure;

    /// <summary>
    /// Provide features to IGameProvider.
    /// </summary>
    public static class GameProviderExtension
    {
        /// <summary>
        /// return the Partition key containing the Square having position point
        /// </summary>
        /// <param name="gameProvider">The game provider</param>
        /// <param name="point">Position of the square</param>
        /// <returns>the partition Key containing this square</returns>
        public static string GetPartitionKey(this IGameProvider gameProvider, Point point)
        {
            // Adding " x >= 0 " avoids conflics in 0
            var subPoint = new Point(
                                       Tools.Div(point.X, GameProvider.SizeOfSubZones),
                                       Tools.Div(point.Y, GameProvider.SizeOfSubZones));
            return subPoint.ToAlphaString();
        }
    }
}
